package com.lemon.cloud.extension;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * @author lemon
 * @version 1.0
 * @description: TODO
 * @date Create by lemon on 2019-09-14 18:10
 */
@Setter
@Getter
@ToString
public class ExtensionCoordinate {
    private String businessScenarioUniqueIdentity;
    private String extensionPointName;
    private Class extensionPointClass;
    private BusinessScenario businessScenario;

    /**
     * @param extensionPointClass 扩展点class
     * @param businessScenario    业务场景
     * @return
     * @description
     * @author lemon
     * @date 2019-09-14 21:56
     */
    public ExtensionCoordinate(Class extensionPointClass, BusinessScenario businessScenario) {
        this.extensionPointClass = extensionPointClass;
        this.extensionPointName = extensionPointClass.getName();
        this.businessScenario = businessScenario;
        this.businessScenarioUniqueIdentity = businessScenario.getUniqueIdentity();
    }

    /**
     * @param extensionPointName             扩展点名称
     * @param businessScenarioUniqueIdentity 业务身份唯一标识
     * @return
     * @description
     * @author lemon
     * @date 2019-09-14 21:56
     */
    public ExtensionCoordinate(String extensionPointName, String businessScenarioUniqueIdentity) {
        this.extensionPointName = extensionPointName;
        this.businessScenarioUniqueIdentity = businessScenarioUniqueIdentity;
    }

    /**
     * @param extensionPointClass 扩展点class
     * @param businessScenario    业务场景
     * @return com.lemon.cloud.extension.ExtensionCoordinate
     * @description
     * @author lemon
     * @date 2019-09-14 21:57
     */
    public static ExtensionCoordinate valueOf(Class extensionPointClass, BusinessScenario businessScenario) {
        return new ExtensionCoordinate(extensionPointClass, businessScenario);
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((businessScenarioUniqueIdentity == null) ? 0 : businessScenarioUniqueIdentity.hashCode());
        result = prime * result + ((extensionPointName == null) ? 0 : extensionPointName.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }

        if (obj == null) {
            return false;
        }

        if (getClass() != obj.getClass()) {
            return false;
        }

        ExtensionCoordinate other = (ExtensionCoordinate) obj;

        if (businessScenarioUniqueIdentity == null) {
            if (other.businessScenarioUniqueIdentity != null) {
                return false;
            }
        } else if (!businessScenarioUniqueIdentity.equals(other.businessScenarioUniqueIdentity)) {
            return false;
        }

        if (extensionPointName == null) {
            if (other.extensionPointName != null) {
                return false;
            }
        } else if (!extensionPointName.equals(other.extensionPointName)) {
            return false;
        }

        return true;
    }

    @Override
    public String toString() {
        return "ExtensionCoordinate [extensionPointName=" + extensionPointName + ", businessScenarioUniqueIdentity=" + businessScenarioUniqueIdentity + "]";
    }
}
